﻿@model IEnumerable<Category>
@{
    Ajax.Dna().Widget()
        .UserPreferences(@<text>
    <div>
        @Html.Global("publishing", "SelectCategory")</div>
    @(Ajax.Dna().TreeView(item.GenerateFieldID("TreeView"))
             .HtmlAttributes(new { style = "height:200px;border:1px solid #cccccc;overflow:auto;padding-top:10px;" })
             .Options(opts =>
             {
                 opts.OnNodeSelected = "$(\"#" + item.GenerateFieldID("CategoryID") + "\").val($(node).attr(\"key\"));";
                 opts.SinglePathExpand = true;
             })
             .ExpandedLevel(1)
             .SelectNode("key", item.UserPreferences["CategoryID"].ToString())
             .Bind(((HierarchicalNodeProviderBase)ViewBag.Provider).RootNode, node =>
             {
                 node.NavigateUrl = "javascript:void(0);";
                 node.ImageUrl = Url.Content("~/content/images/icon_cat_16.gif");
                 return true;
             }, true)
             .GetHtml()
        )
    <input type="hidden" value="@item.GetInt("CategoryID")" id="@item.GenerateFieldID("CategoryID")"
    name="@item.GenerateFieldID("CategoryID")" />
    <div>
        <div>
            @Html.Global("publishing", "DisplayRows")</div>
        <div>
            @Ajax.Dna().Number(item.GenerateFieldID("Rows"), item.GetInt("Rows")).GetHtml()
        </div>
    </div>
    <div>
        <div>
            @Html.Global("publishing", "DisplayTextLen")</div>
        <div>
            @Ajax.Dna().Number(item.GenerateFieldID("TextLen"), item.GetInt("TextLen")).GetHtml()
        </div>
        <div>
            (
            @Html.Global("publishing", "DisplayTextLenTip"))</div>
    </div>
    <div>
        @Ajax.Dna().Checkbox(item.GenerateFieldID("ShowAuthor"), "Show post user", (bool)item.UserPreferences["ShowAuthor"]).GetHtml()
    </div>
    <div style="clear: left; overflow: hidden;">
        @Ajax.Dna().Checkbox(item.GenerateFieldID("ShowDate"), "Show post date", (bool)item.UserPreferences["ShowDate"]).GetHtml()
        <span style="clear: left;"></span>
    </div>
    </text>)
        .Content(widget =>
        {
            Ajax.Dna().Tabs(widget.GenerateFieldID("HeadLineTabs"))
                .Options(opts =>
                {
                    opts.ActiveTabEvent = DomEvents.MouseOver;
                })
                .Views(views =>
                {
                    foreach (var cat in Model)
                    {
                        var children = cat.Articles.OrderByDescending(a => a.Posted).Take(widget.GetInt("Rows"));
                        views.Add(cat.Title).Template(@<text>
    <ul class="d-post-items">
        @foreach (var child in children)
        {
            var article = new ArticleWrapper(child);
            if (!article.IsOwner(User.Identity.Name))
            {
                if ((article.IsPrivate) || (!article.IsPublished))
                {
                    continue;
                }
            }
            <li><a href="@article.PermaLink" title="@(string.IsNullOrEmpty(article.Summary) ? article.Title : Html.Encode(article.Summary))">
                @((widget.GetInt("TextLen")) > -1 ? Html.Cut(article.GetGlobalizationContent().Title, widget.GetInt("TextLen")) : article.GetGlobalizationContent().Title)</a>
                @Publishing.PostStateImage(article, Url)
                @if (widget.GetData<bool>("ShowAuthor"))
                { 
                    <span style="float: right;">by
                        @Html.UserLink(article.UserName)</span>
                }
                @if (widget.GetData<bool>("ShowDate"))
                { 
                    <span style="float: right; margin-right: 5px;">
                        @article.Posted.ToShortDateString()</span>
                }
            </li>
        }
    </ul>
    </text>);
                    }
                }).Render();
        })
        .Render();
}
